/**
 * Copyright (c) 2016-2019 九点科技 All rights reserved.
 *
 * http://www.9dyun.cn
 *
 * 版权所有，侵权必究！
 */
package com.dian.modules.inv.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dian.common.server.CommonService;
import com.dian.common.utils.Date;
import com.dian.common.utils.ListUtils;
import com.dian.common.utils.MapUtils;
import com.dian.modules.inv.dao.InLineDao;
import com.dian.modules.inv.entity.InHeadEntity;
import com.dian.modules.inv.entity.InLineEntity;
import com.dian.modules.inv.service.InLineService;
import com.dian.modules.inv.vo.GoodsStockVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

/**
 * 入库单明细服务实现类
 *
 * @author xiaolai
 * @email xiaolai@9dyun.cn
 * @date 2019-06-11 00:12:45
 */
@Service("InLineService")
public class InLineServiceImpl extends ServiceImpl<InLineDao, InLineEntity> implements InLineService {

    @Autowired
    private  CommonService commonService;

    @Autowired
    public InLineService inLineService;


    @Override
    public boolean updateInfo(InHeadEntity inHeadEntity) {
        List<InLineEntity> lineList=inHeadEntity.getInLineEntityList();
        ListUtils.setPropertyValue(lineList,"inId",inHeadEntity.getId());
        ListUtils.setPropertyValue(lineList,"warehouseId",inHeadEntity.getWarehouseId());
        ListUtils.setPropertyValue(lineList,"warehouseCode",inHeadEntity.getWarehouseCode());
        ListUtils.setPropertyValue(lineList,"warehouseName",inHeadEntity.getWarehouseName());
        this.removeByMap(new MapUtils().put("in_id", inHeadEntity.getId()));
        this.saveBatch(lineList);
        return true;

    }

    @Override
    public boolean deleteInfo(Long id) {
        return this.remove(new QueryWrapper<InLineEntity>().eq("in_id",id));

    }

    @Override
    public List<InLineEntity> queryList(Long id) {
        return this.list(new QueryWrapper<InLineEntity>().eq("in_id",id));

    }

    /**
     * 修改明细入库月份
     * @param id
     * @return
     */
    @Override
    public boolean updateInMonth(Long id,Integer state) {
        this.baseMapper.updateInMonth(id,new Date().toText2(),state);
        return true;
    }
    /**
     * 查询指定商品本月有效入库数量
     * @param goodsStockVO
     * @return
     */
    @Override
    public GoodsStockVO queryInGoodsQty(GoodsStockVO goodsStockVO){
       return  this.baseMapper.queryInGoodsQty(
                goodsStockVO.getWarehouseId(),
                new Date().toText2(),
                goodsStockVO.getGoodsId(),
                goodsStockVO.getColorNumber(),
                goodsStockVO.getItemGrade()
               );
    }
}
